package com.jsmile.cloud.msgcenter.pay.model;

import java.util.Date;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.jsmile.cloud.msgcenter.api.constants.MsgConstants;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.IdUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author 龚亮
 * @version 1.0
 * @desc 为了薪资破万，还是睡一会儿吧...!
 * @date 2020年06月07日 11:19:01
 */
@ApiModel
@Data
@TableName("t_ac_refund_order")
public class RefundOrderInfo extends Model<RefundOrderInfo> {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键id")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    @ApiModelProperty(value = "用户id")
    private Long userId;
    @ApiModelProperty(value = "店铺id")
    private Long shopId;
    @ApiModelProperty(value = "退款单号")
    private String refundNo;
    @ApiModelProperty(value = "微信或者支付宝的订单号")
    private String mchOrderNo;
    @ApiModelProperty(value = "商户订单号")
    private String outTradeNo;
    @ApiModelProperty(value = "1创建（待支付) 2支付完成 3支付失败 ")
    private Integer refundStatus;
    @ApiModelProperty(value = "退款金额 最小单位:分")
    private Long refundAmount;
    @ApiModelProperty(value = "支付appid")
    private String payAppId;
    @ApiModelProperty(value = "支付类型")
    private Integer payType;
    @ApiModelProperty(value = "支付总金额 最小单位:分")
    private Long totalAmount;
    @ApiModelProperty(value = "描述")
    private String remark;
    @ApiModelProperty(value = "创建时间")
    private Date createTime;
    @ApiModelProperty(value = "update_time")
    private Date updateTime;
    @ApiModelProperty(value = "订单编号")
    private Long orderNo;
    @ApiModelProperty(value = "平台id")
    private Integer platformId;
    @ApiModelProperty(value = "业务id")
    private Integer bizCode;
    @ApiModelProperty(value = "支付宝授权token")
    private String authToken;
    @ApiModelProperty(value = "商户id")
    private Long tenantId;

    public static RefundOrderInfo create(PayOrderInfo payOrder, final Long refundAmount, final Long totalAmount) {
        final String refundNo = IdUtil.getSnowflake(MsgConstants.SNOWFLAKE.workerId, MsgConstants.SNOWFLAKE.datacenterId).nextId() + "";
        RefundOrderInfo refundOrderInfo = BeanUtil.toBean(payOrder, RefundOrderInfo.class);
        refundOrderInfo.setCreateTime(new Date());
        refundOrderInfo.setRefundAmount(refundAmount);
        refundOrderInfo.setTotalAmount(totalAmount);
        refundOrderInfo.setRefundNo(refundNo);
        return refundOrderInfo;
    }

}
